<template>
	<view class="sp-section sp-member">
		<!-- 信息 -->
		<view class="sp-member__header">
			<view class="sp-member__header-avatar">
				<image src="../../static/images/avatar.png"></image>
			</view>
			<view class="sp-member__header-name">
				<label>{{ info.username }}</label>
				<text>{{ info.is_manager == 1 ? '管理员' : '员工' }}</text>
			</view>
		</view>
		
		<!-- 设置 -->
		<template v-if="info.is_manager == 1">
			<view class="sp-member__menu">
				<view class="sp-title" @click="$u.route('/pages/member/room')">
					<u-cell class="sp-oa__boxes-name" title="空栏设置"></u-cell>
				</view>
			</view>
			
			<view class="sp-member__menu" style="margin-top: 20rpx;;">
				<view class="sp-title" @click="$u.route('/pages/member/create')">
					<u-cell class="sp-oa__boxes-name" title="创建用户"></u-cell>
				</view>
			</view>
		</template>
		
		<view class="sp-member__menu">
			<view class="sp-title" @click="$u.route('/pages/member/password')">
				<u-cell class="sp-oa__boxes-name" title="修改密码"></u-cell>
			</view>
		</view>
		
		<!-- 开始拍照 -->
		<view class="sp-member__submit">
			<button @click="logout">退出</button>
		</view>
		<text style="color: #ccc; text-align: center; display: block; font-size: 24rpx; padding: 10px;">v1.0.0-Master-睿畜</text>
		
		<!-- #ifdef APP -->
		<wrap-version-update ref="updateRef" id="532443316514885" :auto="false" @error="handleError" @finish="handleFinish"></wrap-version-update>
		<!-- #endif -->
	</view>
</template>

<script>
	import { appid } from '@/config/index.js'
	import { getInfos } from '@/api/task.js'
	
	export default {
		name: 'spMember',
		data() {
			return {
				appid,
				info: {}
			}
		},
		mounted() {
			this.getInfo()
		},
		methods: {
			logout() {
				uni.reLaunch({
					url: '/pages/user/index'
				})
			},
			toCheck() {
				// 主动检查更新，一般用于设置界面中
				// 用法：设置auto为false,当用户点击检查更新时，执行此方法
				this.$refs.updateRef.check();
			},
			handleFinish(res) {
				if (!res.isTest) {
					this.$u.toast('已经是最新版')
				}
			},
			handleError(err) {
				this.$u.toast('更新失败')
			},
			async getInfo() {
				const data = await getInfos()
				// console.log('info', data)
				this.info = data
			}
		}
	}
</script>